<template>
	<view class="animal_user_msg">
		<view class="animal_header">
			<view class="search_header_back">
				<image @click="backGo" src="/static/back.png" mode=""></image>
			</view>
			<view class="animal_header_title">
				<view class="th2">Modify for
				</view>
				<view class="th1">You</view>
			</view>
			<image aspectFit class="msg_header_img" src="/static/msg-bg.png" mode=""></image>
		</view>
		<view class="animal_main">
			<view class="form">
				<view class="email">
					<text>昵称 :</text> <input :disabled="changeFlat" v-model="userInfo.nick_name" type="text">
				</view>
				<view class="password">
					<text>密码 :</text><input :disabled="changeFlat" v-model="userInfo.password" type="password">
				</view>
				<view class="password">
					<text>签名 :</text><input :disabled="changeFlat" placeholder="签名为空" v-model="userInfo.sig"
						type="text">
				</view>
				<view class="btn">
					<u-button @click="changeMsg" :text="changeFlat?'修改信息':'确定修改'"></u-button>
				</view>

			</view>

		</view>
	</view>
</template>

<script>
	import {
		userDesc,
		changeUserMsg
	} from "../../api/index.js"
	export default {
		data() {
			return {
				nick_name: "",
				password: "",
				sig: "",
				changeFlat: true,
				uid: "",
				userInfo: {},
			};
		},
		async onShow() {
			uni.showLoading({
				title: "加载中...",

			})
			this.uid = uni.getStorageSync("uid")
			await this.getUser(this.uid)

		},
		methods: {
			backGo() {
				uni.navigateBack({
					delta: 1
				})
			},
			async changeMsg() {
				this.changeFlat = !this.changeFlat
				if (this.changeFlat) {
					let {
						id,
						nick_name,
						password,
						sig
					} = this.userInfo
					// console.log(id,
					// 	nick_name,
					// 	password,
					// 	sig)
					await changeUserMsg(id,
						nick_name,
						password,
						sig).then((content) => {
						let {
							data: {
								code
							}
						} = content
						if (code == 200) {
							uni.showToast({
								title: "修改成功"
							})
						}
						this.getUser(id)
					})
				}
			},

			async getUser(id) {
				await userDesc(id).then((content) => {
					console.log(content)
					let {
						data: {
							data,
							code
						}
					} = content
					if (code == 200) {
						this.userInfo = data[0]
					}
					uni.hideLoading()
				})
			}

		}
	}
</script>

<style lang="scss">
	.form {
		height: 300px;
		width: 100%;
		padding-top: 30px;

		.email,
		.password {
			display: flex;
			margin: 0 20px;
			padding: 20px 10px;
			margin-bottom: 10px;
			border-bottom: 2px solid #a1b275;

			input {
				margin-left: 10px;
				width: 260px;
			}
		}
	}

	.btn {
		margin: 40px 18px 0;

		.u-button {
			background-color: #a1b275;
			color: white;
			margin-bottom: 20px;
			border-radius: 10px;
		}
	}

	.search_header_back {
		position: absolute;
		top: 10px;
		left: 10px;
		z-index: 1;

		image {

			width: 30px;
			height: 30px;
		}
	}

	.search_header_back {
		position: absolute;
		top: 10px;
		left: 10px;
		z-index: 1;

		image {

			width: 30px;
			height: 30px;
		}
	}

	.animal_user_msg {
		background-color: #a1b275;
	}

	.animal_header {
		width: 100%;
		height: 150px;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.msg_header_img {
		display: block;
		width: 172px;
		height: 100px;
		margin-right: 20px;
		margin-top: 10px;
	}

	.animal_header_title {
		margin-top: 20px;
		margin-left: 40px;
		color: white;
		line-height: 36px;

		.th2 {
			font-size: 28px;
			font-weight: 100;
		}

		.th1 {
			font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
			font-size: 28px
		}
	}

	.animal_main {
		min-height: 517px;
		background-color: #f2f3f3;
		border-radius: 43px 43px 0 0;
	}
</style>